/*
 * @Author: CJF
 * @Email: 1757818940@qq.com
 * @Date: 2022-02-24 16:20:40
 * @LastEditTime: 2022-02-28 15:20:56
 * @Description: 
 */
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
import Login from '../sub-unit/login'
import Register from '../sub-unit/login/register'
import Home from '../sub-unit/home'
import Commom from '../sub-unit/commom/NotFound'
import Mine from '../sub-unit/mine'
import Mlassify from '../sub-unit/classify'
import Shoppingcart from '../sub-unit/shoppingcart'
import Details from '../sub-unit/details'
let meta = { ling: true }
const router = new Router({
    //路由模式
    mode: 'history',
    //配置路由
    routes: [
        //默认路由  
        { path: '/', redirect: '/login' },
        { path: '/login', component: Login, meta },
        { path: '/register', component: Register, meta },
        { path: '/home', component: Home },
        { path: '/mine', component: Mine},
        { path: '/classify', component: Mlassify },
        { path: '/shoppingcart', component: Shoppingcart },
        {path:'/details',component:Details},
        //输入没有的ip
        { path: '*', component: Commom, meta }

    ]

})

router.beforeEach(function(to,from,next){
    let Ling=to.meta.ling
    if(Ling){
        next()
    }else{
        let token = sessionStorage.getItem('token')
        
        if(!!token&&token!='null'){
            next()
        }else{
            next('/login')
        }
    }


 })
export default router